home *** CD-ROM | disk | FTP | other *** search
- {$M 8192,0,0}
- {$G+}
- uses files, alloc;
- {
- Plasma v1.0
- by Maple Leaf, 1996
- ------------------------
- The EXE file requires the external file PLASMA.DAT
- }
- var
- plasma : pointer;
- movement : pointer;
- colour : pointer;
- count : word;
-
- Procedure BRead(var f:file; var dest; count:longint);
- var bcopy,r:word;copied:longint;
- begin {$i-}
- copied:=0;
- repeat
- if count>64000 then bcopy:=64000 else bcopy:=word(count);
- blockread(f,ptr(seg(dest)+(copied div 16),ofs(dest)+(copied mod 16))^,bcopy,r);
- copied:=copied+bcopy;
- count:=count-bcopy;
- until count<=0;
- end;
-
- Procedure FreeMemory;
- begin
- if not free(plasma) or
- not free(movement) or
- not free(colour) then writeln('Error deallocating memory. The system will probably crash.');
- end;
-
- procedure LoadPlasm;
- var f:file; r:word;
- begin
- plasma:=malloc(9600*16);
- movement:=malloc(2500*16);
- colour:=malloc(1920*16);
- if (plasma=nil) or (movement=nil) or (colour=nil) then begin
- writeln('Sorry, not enough memory.');
- free(plasma); free(movement); free(colour);
- halt;
- end;
- openforinput(f,'plasma.dat');
- if ioresult<>0 then begin
- writeln('Cannot load file PLASMA.DAT. Generate it first with GENP progs.');
- FreeMemory;
- halt
- end;
- BRead(f,plasma^,9600*16); { Read plasma cloud }
- BlockRead(f,movement^,40000,r); { Read movement table }
- BlockRead(f,colour^,30720,r); { Read colour transition table }
- closefile(f);
- end;
-
- Procedure InitGraph;near;assembler;
- asm
- mov ax,13h
- int 10h
- end;
-
- Procedure CloseGraph;near;assembler;
- asm
- mov ax,3
- int 10h
- end;
-
- Procedure ShowPlasm;near;assembler;
- asm
- mov count,0
- mov ax,0a000h
- mov es,ax
- sub ax,ax
- @MainLoop:
- mov dx,3DAh
- in al,dx
- test al,8
- je @MainLoop { Wait for vertical retrace }
- mov bx,count
- mov si,bx
- shl si,1
- add si,bx { SI = count*3 }
- { Set a palette ... }
- mov dx,3c8h
- mov al,1
- out dx,al
- inc dx
- mov cx,0FFh
- push ds
- mov ds,word ptr colour[2]
- cld
- @l3:outsb
- outsb
- outsb
- loop @l3
- pop ds { Restore DS register }
- mov di,bx { BX is already = to COUNT }
- shl di,2
- push ds
- mov ds,word ptr movement[2]
- mov si,[di] { point 1 }
- mov bx,[di+2] { point 2 }
- pop ds
- push ds
- mov ds,word ptr plasma[2] { Segment of plasma's start }
- mov di,40 { Starting offset }
- mov ch,200 { y loop = 200 pixels }
- @l1:mov cl,60 { x loop = 60*4 = 240 pixels }
- @l2:db 66h; lodsw { Load 4 bytes from source }
- db 66h; add ax,[si+bx] { Add 4 source pixels }
- db 66h; stosw { Put bytes as pixels }
- dec cl
- jnz @l2 { Do the second loop }
- add di,80
- sub si,240 { Reset source }
- mov dx,ds
- add dx,32
- mov ds,dx { DS:=DS+32, this means 32*16=512 bytes down in source memory }
- dec ch
- jnz @l1 { Do the first loop }
- pop ds
- inc count
- cmp count,10000
- jb @NoReset
- mov count,0 { Reset counter at the end of a cycle }
- @NoReset:
- mov ah,0bh
- int 21h
- or al,al
- jz @MainLoop { repeat until keypressed ... }
- end;
-
- begin
- LoadPlasm;
- InitGraph;
- ShowPlasm;
- CloseGraph;
- FreeMemory;
- end.